<style>
    .notice a {color: blue; font-size: 12px; font-weight: 700;margin-left: 4px; margin-right: 4px;}
    .notify {border-color: #FFD324;font-size: 12px; }
    .processBarBg {border:1px solid #999999; width:98%; margin:5px; height:25px;line-height:25px;padding:1px; background:#EEEEEE;}
    .processBar {background:#3366cc; width:0px; padding-bottom:1px;overflow:hidden;}
</style>
<form method="post" id="import_form"
    action="index.php?app=ome&ctl=admin_order_replace&act=doreplace" class="tableform">
    <input type="hidden" name="order_ids" value="<{$order_ids}>" id="order_ids">
  <div class="division">
    <h4>当前共<{$ordercount}>个订单<br></h4>
    <div id="information" class="division" style="display:none;">
      <div style="color:green;"><b>结果信息如下：</b></div>
      <div id="errorInfo" style="width:450px;height:150px;padding:5px;overflow-y:auto;line-height:150%;border:1px solid #999;"></div>
  </div>
  <div class="gridlist" >
    <table class="nosplit" width="100%" cellspacing="0" cellpadding="0" border="0" >

      <tr>
        <th>原物料:</th> <td><input type="text" name="material" id="material"></td>
      </tr>
      <tr>
        <th>替换物料:</th> <td><input type="text" name="material_replace" id="material_replace"></td>
      </tr>
    </table>
  </div>

  <div class="table-action">
 <{button class="btn-primary" id='btn-submit' label="开始" type="button"}>
 <{button label="关闭" type="botton" isCloseDialogBtn="true" }>
  </div>
</div>
</form>
<script>
(function(){
    $('btn-submit').addEvent('click',function(){
        var order_ids = $('order_ids').getValue();
        var material  = $('material').getValue();
        var material_replace = $('material_replace').getValue();
        if(material.toUpperCase() == material_replace.toUpperCase()){
          MessageBox.show('替换物料和原物料不能为同一物料');
          return;
        }
        if(!order_ids || !material || !material_replace){
          MessageBox.show('请先写入替换信息');
          return;
        }
        $('information').style.display ='none';
        $('errorInfo').set('html', '');
        MessageBox.success('正在替换...');
        $('btn-submit').set('disabled', 'disabled');
        $('btn-submit').set('html', '<span><span>正在替换...</span></span>');
        new Request({
                url:'index.php?app=ome&ctl=admin_order_replace&act=doreplace',
                method:'post',
                data:{'order_ids':order_ids,'material':material,'material_replace':material_replace},
                onRequest: function(){
                    MessageBox.show('正在替换请稍等...');
                },
                onSuccess:function(response){
                    json = JSON.decode(response);
                    if(json.result && json.result == 'succ'){
                        MessageBox.success('操作结束！');
                        $('btn-submit').set('html', '<span><span>开始</span></span>');
                        $('btn-submit').set('disabled', '');
                        $('information').style.display ='';
                        var errorInfo = '';
                        for(var key=0; key<json['msg'].length;key++){
                            errorInfo = errorInfo + json['msg'][key] + '<br />';
                        }
                        $('errorInfo').set('html', errorInfo);
                    }
                    if(json.result && json.result == 'fail'){
                        console.log(json['msg']);
                        MessageBox.success('操作结束！');
                        $('information').style.display ='';
                        var errorInfo = '';
                        for(var key=0; key<json['msg'].length;key++){
                            errorInfo = errorInfo + json['msg'][key] + '<br />';
                        }
                        $('errorInfo').set('html', errorInfo);
                        $('btn-submit').set('html', '<span><span>开始</span></span>');
                        $('btn-submit').set('disabled', '');
                    }
                },
                onError:function(Error){
                    return MessageBox.error('操作失败！');
                }

            }).send();
    });
})();

</script>